home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / graphic import.export / start code / multipleimages.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  2.7 KB  |  88 lines

  1. // Graphics Importer and Exporter Samples
  2. // This example demonstrates how to display multiple images
  3. // Originally written by Sam Bushell for QuickTime "Live" '99
  4. // WWDC 2000 Introduction to QuickTime
  5.  
  6. #include "MacShell.h"
  7.  
  8. void MultipleImage( void )
  9. {
  10.     OSErr err = noErr;
  11.     Handle hOpenTypeList = NewHandle(0);
  12.     long  numTypes = 0;
  13.     FSSpec    theFSSpec;
  14.     GraphicsImportComponent importer = 0;
  15.     Rect naturalBounds, windowBounds;
  16.     WindowPtr window = NULL;
  17.     unsigned long imageCount, imageIndex;
  18.     ImageDescriptionHandle desc = NULL;
  19.     MatrixRecord matrix;
  20.  
  21.     BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
  22.     HLock( hOpenTypeList );
  23.     
  24.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  25.     DisposeHandle( hOpenTypeList );
  26.     if ( err ) return;
  27.     
  28.     // locate and open a graphics importer component
  29.     err = GetGraphicsImporterForFile( &theFSSpec, &importer );
  30.     
  31.     // get the native size of the image associated with the importer
  32.     err = GraphicsImportGetNaturalBounds( importer, &naturalBounds );
  33.     windowBounds = naturalBounds;
  34.     OffsetRect( &naturalBounds, 10, 45 );
  35.     window = NewCWindow( NULL, &naturalBounds, "\pMultiple Images", true, documentProc, (WindowPtr)-1, true, 0);
  36.     
  37.     // set the graphics port for drawing
  38.     err = GraphicsImportSetGWorld( importer, GetWindowPort(window), NULL );
  39.     
  40.     // ask the graphics importer how many images there are in this file
  41. // Step 1. Insert GetImageCount.clp here...
  42.  
  43.     
  44.     for( imageIndex = 1; imageIndex <= imageCount; imageIndex++ ) {    
  45.         // set the index value for the image we want to draw
  46. // Step 2. Insert SetImageIndex.clp here...
  47.  
  48.         
  49.         // each image in the file can have different dimensions, depth, etc.
  50.         // if the image has an alpha, use StraightAlpha graphics mode to draw
  51. // Step 3. Insert SetGraphicsMode.clp here...
  52.  
  53.         DisposeHandle( (Handle)desc );
  54.         
  55.         // set up the matrix
  56. // Step 4. Insert SetMatrix.clp here...
  57.  
  58.         SetPortWindowPort( window );
  59.         EraseRect( &windowBounds );
  60.         
  61.         // draw the image
  62.         err = GraphicsImportDraw( importer );
  63.  
  64.         pause();
  65.     }
  66.     
  67.     // draw the images again but this type don't erase
  68.     for( imageIndex = 2; imageIndex <= imageCount; imageIndex++ ) {
  69.         err = GraphicsImportSetImageIndex( importer, imageIndex );
  70.         
  71.         err = GraphicsImportGetImageDescription( importer, &desc );
  72.         if( (*desc)->depth == 32 )
  73.             err = GraphicsImportSetGraphicsMode( importer, graphicsModeStraightAlpha, NULL );
  74.         else
  75.             err = GraphicsImportSetGraphicsMode( importer, ditherCopy, NULL );
  76.         DisposeHandle( (Handle)desc );
  77.         
  78.         SetIdentityMatrix( &matrix );
  79.         GraphicsImportGetDefaultMatrix( importer, &matrix );
  80.         err = GraphicsImportSetMatrix( importer, &matrix );
  81.  
  82.         err = GraphicsImportDraw( importer );
  83.  
  84.         pause();
  85.     }
  86.  
  87.     CloseComponent( importer );
  88. }